/**
 * Created by sks on 2016/10/10.
 */
var tagInfo=$("input[name=tagInfo]").val();
console.log(tagInfo);
var averageAbility=$("input[name=average_ability]").val();
console.log(averageAbility);
tagInfo=eval('('+tagInfo+')');
console.log(tagInfo);
var xhln='',znln='',zhln='';
var xiance_tag_arr_info=tagInfo[0].xiance_tag_arr_info;
var zhlx_tag_arr_info=tagInfo[1].zhlx_tag_arr_info;
var zhlx_not_leared_tag_code_info=tagInfo[2].zhlx_not_leared_tag_code_info;
for(var i=0;i<xiance_tag_arr_info.length;i++){
    xhln += xiance_tag_arr_info[i].name+"<br/>";
}
for(var i=0;i<zhlx_not_leared_tag_code_info.length;i++){
    znln += zhlx_not_leared_tag_code_info[i].name+"<br/>";
}
for(var i=0;i<zhlx_tag_arr_info.length;i++){
    zhln += zhlx_tag_arr_info[i].name+"<br/>";
}
var topicId=$("input[name=topicId]").val();
var zhlx_not_leared_num=tagInfo[0].xiance_has_learned_num,zhlx_has_leared_num=tagInfo[1].zhlx_has_leared_num,xiance_has_learned_num=tagInfo[2].zhlx_not_leared_num;
console.log(zhlx_not_leared_num);
console.log(zhlx_has_leared_num);
console.log(xiance_has_learned_num)
var all=zhlx_not_leared_num+zhlx_has_leared_num+xiance_has_learned_num;
var myChart = echarts.init(document.getElementById('learned_charts'));
var option = {
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)",
        formatter: function (params) {
//                    console.log(JSON.stringify(params));
            return "所占的比例："+(params.data.value/all).toFixed(3)*100+'%'+'<br/>'+"<br/>"+ params.data.text;
        }
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['专题学习后仍未掌握的','专题学习后已掌握的知识点比例','先行测试判断已掌握的知识点比例']
    },

    series : [
        {
            name: '学习情况',
            type: 'pie',
            radius: '55%',
            data:[
                {
                    value:xiance_has_learned_num,
                    name:'专题学习后仍未掌握的',
                    text:'专题学习后仍未掌握的知识点列表：'+'<br/>'+znln
                },
                {
                    value:zhlx_has_leared_num,
                    name:'专题学习后已掌握的知识点比例',
                    text:'专题学习后已掌握的知识点列表：'+'<br/>'+zhln
                },
                {
                    value:zhlx_not_leared_num,
                    name:'先行测试判断已掌握的知识点比例',
                    text:'先行测试判断已掌握的知识点列表：'+'<br/>'+xhln
                }
            ]
        }
    ],
};
myChart.on('click', function (param) {
    var index = param.dataIndex;
    if(index===1){
        $(".yx-button").find("button").trigger("click");
    }
    if(index===0){
        if(xiance_has_learned_num!==0){
            window.open(HOST+'index/errorbook/index/topicId/'+topicId,"_self");
        }

    }
});
myChart.setOption(option);
if(averageAbility>0&&averageAbility<=0.2){
    $("#star-one").show();
    $("#one-stars").show();
}else if(averageAbility>0.2&&averageAbility<=0.4){
    $("#star-two").show();
    $("#two-stars").show();
}else if(averageAbility>0.4&&averageAbility<=0.6){
    $("#star-three").show();
    $("#three-stars").show();
}else if(averageAbility>0.6&&averageAbility<=0.8){
    $("#star-four").show();
    $("#four-stars").show();
}else{
    $("#star-five").show();
    $("#five-stars").show();
}